#'###########################################
#'                                          #
#'  ------------------------------------    #
#'  |     COIN     __                  |    #
#'  |            >(' )                 |    #
#'  |              )/                  |    #
#'  |             /  `----/            |    #
#'  |             \  ~=- /             |    #
#'  |   ~^~^~^~^~^~^~^~^~^~^~^~^~^~^   |    #
#'  ------------------------------------    #
#'                                          #
#'###########################################


rm(list=ls())

#'#
#'# Chemins de travail
#'#
R_ROOT <- "C:/UQAR/Recherche/Maitrise/Donnees"
R_WORKING_DIRECTORY <- file.path(R_ROOT, "R")
R_DATA_PATH <- file.path(R_ROOT, "Donnees")
R_RESULTS_PATH <- file.path(R_ROOT, "Resultats")


#'#
#'# Chargement des dependances
#'# 


source(file.path(R_WORKING_DIRECTORY, "Utils/loadDependencies.R"))

#'#################################################################################################
#'#                                                                                              ##
#'#                                 Comparaison avec le gps                                      ##
#'#                                                                                              ##
#'#################################################################################################


#'#
#'# Fichiers de travail
#'#

STATIC_WORKING_DIR <- file.path(R_DATA_PATH, "Bylot/Fixe")
MOBILE_WORKING_DIR <- file.path(R_DATA_PATH, "Bylot/Mobile")

STATIC_DEST_DIR <- file.path("C:/UQAR/Recherche/Maitrise/Article/Manuscrit/Data/Static")
MOBILE_DEST_DIR <- file.path("C:/UQAR/Recherche/Maitrise/Article/Manuscrit/Data/Mobile")

static.data <- loadData(STATIC_WORKING_DIR, static=TRUE, raw=TRUE, argoscolumns=names(ARGOS_COLUMN_NAMES), gpscolumns=c("Position",	"Time",	"Altitude",	"Leg.Length",	"Leg.Time",	"Leg.Speed",	"Leg.Course"))
lapply(static.data, saveArticleData, destdir=STATIC_DEST_DIR, static=TRUE)

mobile.data <- loadData(MOBILE_WORKING_DIR, static=FALSE, raw=TRUE, argoscolumns=names(ARGOS_COLUMN_NAMES), gpscolumns=c("Position",	"Time",	"Altitude",	"Leg.Length",	"Leg.Time",	"Leg.Speed",	"Leg.Course"))
lapply(mobile.data, saveArticleData, destdir=MOBILE_DEST_DIR, static=FALSE)


statErrors <- getErrors(static.data, static=TRUE, compiled=FALSE)

statPos <- rbindlist(lapply(statErrors, function(x){return(x@truePos)}))
write.csv(statPos, file.path("C:/UQAR/Recherche/Maitrise/Article/Manuscrit/Data/Positions_tests_Statiques.csv",sep=""),
    row.names=FALSE)

tracks <- rbindlist(lapply(mobile.data, function(x){return(x@gps)}))
write.csv(tracks, file.path("C:/UQAR/Recherche/Maitrise/Article/Manuscrit/Data/Trajectoires_mobiles.csv",sep=""),
    row.names=FALSE)

mobile.data
